package Sort;

import java.util.Arrays;
import java.util.Random;

public class TestSort {

    public static void orderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i]=i;
        }
    }

    public static void notOrderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i]= array.length-i;
        }
    }

    public static void randomArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i]= random.nextInt(100000);
        }
    }

    public static void testInsertSort(int[] array){
        int[] arrays = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(arrays);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序用时："+(endTime-startTime));
    }

    public static void testShellSort(int[] array){
        int[] arrays = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(arrays);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序用时："+(endTime-startTime));
    }

    public static void testSelectSort(int[] array){
        int[] arrays = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(arrays);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序用时："+(endTime-startTime));
    }

    public static void testHeapSort(int[] array){
        int[] arrays = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(arrays);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序用时："+(endTime-startTime));
    }

    public static void testQuickSort(int[] array){
        int[] arrays = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(arrays);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序用时："+(endTime-startTime));
    }

    public static void main1(String[] args) {
        int[] array = new int[100000];
        //notOrderArray(array);
        //orderArray(array);
        randomArray(array);
        testShellSort(array);
        testInsertSort(array);
        //Sort.insertSort(array);
        //System.out.println(Arrays.toString(array));
    }

    public static void main2(String[] args) {
        int[] array = new int[100000];
        randomArray(array);
        Sort.mergeSort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main(String[] args) {
        int[] array = {29,81,16,4,2,3,45,89,22};
        Sort.mergeSortNor(array);
        System.out.println(Arrays.toString(array));
    }
}
